Imports Security.Entities
Imports DataAccess.Base
Imports System.ComponentModel

Public Class BackupViewDAO
    Inherits ViewDAO(Of BackupView)

    Public Sub New()
        Me.TableName = "Security_BackupsView"
        Me.IDColumn = "BackupId"
    End Sub

    <DataObjectMethod(DataObjectMethodType.Select)> _
    Public Function ListWithFilters(ByVal userId As Guid, ByVal tenantId As Guid, ByVal fromDate As String, ByVal toDate As String) As IList(Of BackupView)
        Dim query As String = String.Format("SELECT * FROM [{0}]", Me.TableName)
        Dim where As String = String.Empty
        Dim fromD As DateTime
        Dim toD As DateTime

        If userId <> Guid.Empty Then
            where &= String.Format("UserId = '{0}' AND ", userId)
        End If

        If tenantId <> Guid.Empty Then
            where &= String.Format("TenantId = '{0}' AND ", tenantId)
        End If

        If DateTime.TryParse(fromDate, fromD) Then
            If DateTime.TryParse(toDate, toD) Then
                where &= String.Format("Date BETWEEN '{0:yyyy/MM/dd}' AND '{1:yyyy/MM/dd}' AND ", fromD, toD)
            End If
        End If

        If Not String.IsNullOrEmpty(where) Then
            query &= " WHERE " & where.Substring(0, where.Length - 5)
        End If

        Return ListByQuery(query)
    End Function
End Class
